package org.rain.core.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.rain.common.model.R;
import org.rain.core.BaseController;
import org.rain.core.sys.model.entity.SysDict;
import org.rain.core.sys.model.req.SysDictItemReq;
import org.rain.core.sys.model.req.SysDictReq;
import org.rain.core.sys.model.resp.SysDictItemResp;
import org.rain.core.sys.model.resp.SysDictResp;
import org.rain.core.sys.service.ISysDictService;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * created by yangtong on 2025/4/8 16:45:39
 * <br/>
 */
@RestController
@RequestMapping("/sys/dict")
@Tag(name = "字典")
public class SysDictController extends BaseController<SysDict, ISysDictService> {

    /**
     * 分页查询字典
     */
    @GetMapping("pageDict")
    @Operation(summary = "分页查询字典", description = "分页查询字典")
    public R<IPage<SysDictResp>> pageDict(@ParameterObject SysDictReq dictReq) {
        return R.success(baseService.pageDict(dictReq));
    }

    /**
     * 新增或编辑字典
     */
    @PostMapping("saveOrUpdateDict")
    @Operation(summary = "新增或编辑字典", description = "新增或编辑字典")
    public R<String> saveOrUpdateDict(SysDictReq dictReq) {
        baseService.saveOrUpdateDict(dictReq);
        return R.success("操作成功");
    }

    /**
     * 根据id删除字典
     */
    @DeleteMapping("deleteDict")
    @Operation(summary = "根据id删除字典", description = "根据id删除字典")
    public R<String> deleteDict(String id) {
        baseService.deleteDict(id);
        return R.success("删除成功");
    }

    /**
     * 分页查询字典
     */
    @GetMapping("listDictItem")
    @Operation(summary = "查询字典项", description = "查询字典项")
    public R<List<SysDictItemResp>> listDictItem(@ParameterObject SysDictItemReq dictItemReq) {
        return R.success(baseService.listDictItem(dictItemReq));
    }

    /**
     * 新增或编辑字典项
     */
    @PostMapping("saveOrUpdateDictItem")
    @Operation(summary = "新增或编辑字典", description = "新增或编辑字典")
    public R<String> saveOrUpdateDictItem(SysDictItemReq dictItemReq) {
        baseService.saveOrUpdateDictItem(dictItemReq);
        return R.success("操作成功");
    }

    /**
     * 根据id删除字典项
     */
    @DeleteMapping("deleteDictItem")
    @Operation(summary = "根据id删除字典项", description = "根据id删除字典项")
    public R<String> deleteDictItem(String id) {
        baseService.deleteDictItem(id);
        return R.success("删除成功");
    }

}
